package edu.hitsz;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import edu.hitsz.application.Game;
import edu.hitsz.application.Main;
import edu.hitsz.thread.MusicThread;

public class StartMenu extends JPanel{
    private JPanel mainPanel;
    private JButton easyButton;
    private JButton normalButton;
    private JButton hardButton;
    private JPanel buttonPanel;
    private JPanel soundPanel;
    private JComboBox soundSelect;
    private JLabel soundLabel;

    private Game game = new Game();
    private Game.ModeTemplateMethod mode;


    public StartMenu() {
        easyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.cardPanel.add(game);
                mode = game.new Easy();
                mode.action();
                Main.cardLayout.last(Main.cardPanel);
                game.setMode(0);
            }
        });
        normalButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.cardPanel.add(game);
                mode = game.new Normal();
                mode.action();
                Main.cardLayout.last(Main.cardPanel);
                game.setMode(1);
            }
        });
        hardButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.cardPanel.add(game);
                mode = game.new Hard();
                mode.action();
                Main.cardLayout.last(Main.cardPanel);
                game.setMode(2);
            }
        });
        soundSelect.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getItem()=="开"){
                    game.music = 1;
                } else {
                    game.music = 0;
                }
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("startMenu");
        frame.setContentPane(new StartMenu().mainPanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public Game getGame() {
        return game;
    }
}
